﻿#include "BaseGraphicsItem.h"
#include "GraphicsDef.h"

namespace OfUI {

	BaseGraphicsItem::BaseGraphicsItem(QGraphicsItem *parent /*= 0*/)
		: QGraphicsItem(parent)
		, m_nType(ItemType::NONE_TYPE)
		, m_eItemState(STATE_NORMAL)
		, m_dViewScale(1)
	{
		static int nAscID = 0;
		m_nId = nAscID++;
		__super::setZValue(getAscZValue());

		// 设置默认字体画笔
		m_font = QFont("Arial", 13, QFont::Bold);
		m_penMap[STATE_NORMAL] = QPen(QColor("#00E4FF"), 2);
		m_penMap[STATE_SELECT] = QPen(QColor("#2453A4"), 2);
		m_penMap[STATE_DISABLE] = QPen(QColor("#00E4FF"), 2);
	}

	BaseGraphicsItem::~BaseGraphicsItem()
	{
		emit signalDestroyed();
	}

	int BaseGraphicsItem::getId() const
	{
		return m_nId;
	}

	void BaseGraphicsItem::setZValue(qreal value)
	{
		if (value != zValue())
		{
			__super::setZValue(value);
			emit signalDataChanged();
		}
	}

	void BaseGraphicsItem::setType(int nType)
	{
		m_nType = nType;
	}

	int BaseGraphicsItem::getType() const
	{
		return m_nType;
	}

	void BaseGraphicsItem::setState(const ItemState & state)
	{
		if (state != m_eItemState)
		{
			m_eItemState = state;
			update();
			emit signalStateChanged(m_eItemState);
		}
	}

	BaseGraphicsItem::ItemState BaseGraphicsItem::getState() const
	{
		return m_eItemState;
	}

	void BaseGraphicsItem::setViewScale(double dScale)
	{
		m_dViewScale = dScale;
		update();
	}

	double BaseGraphicsItem::getViewScale() const
	{
		return m_dViewScale;
	}

	void BaseGraphicsItem::setFont(const QFont& font)
	{
		m_font = font;
		update();
	}

	QFont BaseGraphicsItem::getFont() const
	{
		return m_font;
	}

	void BaseGraphicsItem::setPen(const ItemState & eState, const QPen & pen)
	{
		m_penMap[eState] = pen;
		update();
	}

	QPen BaseGraphicsItem::getPen(const ItemState & eState) const
	{
		return m_penMap[eState];
	}

	bool BaseGraphicsItem::isAdding() const
	{
		return false;
	}

	bool BaseGraphicsItem::isEditing() const
	{
		return false;
	}

	bool BaseGraphicsItem::isVaild() const
	{
		return false;
	}

	BaseGraphicsItem::MouseDragType BaseGraphicsItem::select(const QPointF& point, int* selType /*= nullptr*/) const
	{
		return DRAG_NONE;
	}

	void BaseGraphicsItem::cursor(const QPointF& point, QCursor& cursor) const
	{
	}

	void BaseGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
	{
		Q_UNUSED(event);
	}

	void BaseGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
	{
		Q_UNUSED(event);
	}

	void BaseGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
	{
		Q_UNUSED(event);
	}

	void BaseGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
	{
		Q_UNUSED(event);
	}

	void BaseGraphicsItem::focusOutEvent(QFocusEvent * event)
	{
		Q_UNUSED(event);
	}

}
